/*
* Copyright (c) 2019 Apple Inc. All Rights Reserved.
*
* @APPLE_LICENSE_HEADER_START@
*
* This file contains Original Code and/or Modifications of Original Code
* as defined in and that are subject to the Apple Public Source License
* Version 2.0 (the 'License'). You may not use this file except in
* compliance with the License. Please obtain a copy of the License at
* http://www.opensource.apple.com/apsl/ and read it before using this
* file.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
* Please see the License for the specific language governing rights and
* limitations under the License.
*
* @APPLE_LICENSE_HEADER_END@
*/


#import <XCTest/XCTest.h>
#include <utilities/SecCFWrappers.h>

unsigned char _test_sign_no_email_p12[2735];

@interface SecItemTests : XCTestCase

@end

@implementation SecItemTests

- (void)setUp {
    [self deleteAll];
}

- (void)tearDown {
    [self deleteAll];
}

- (void)testAddGenericPassword {
    NSDictionary *attrs;

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");
    XCTAssertNil(attrs[@"OSStatus"], "should have no error");
}

- (void)testAddTwoGenericPassword {
    NSDictionary *attrs;

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");
    XCTAssertNil(attrs[@"OSStatus"], "should have no error");

    attrs = [self addGenericPassword:@"delete-me2s" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");
    XCTAssertNil(attrs[@"OSStatus"], "should have no error");
}

- (void)testAddCollidingGenericPassword {
    NSDictionary *attrs;

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");
    XCTAssertEqual([attrs[@"OSStatus"] integerValue], errSecDuplicateItem, "should have duplicate item");
}


- (void)testMoveGenericPassword {
    NSDictionary *attrs;

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");

    attrs = [self addGenericPassword:@"delete-me" service:@"delete-me"];
    XCTAssertNotNil(attrs, "should create genp");
    XCTAssertEqual([attrs[@"OSStatus"] integerValue], errSecDuplicateItem, "should have duplicate item");

    XCTAssertEqual([self moveGenericPassword:@"delete-me" service:@"delete-me"
                                  newAccount:@"delete-me2" newService:@"delete-me2"],
                   noErr);

    XCTAssertEqual([self moveGenericPassword:@"delete-me" service:@"delete-me"
                                  newAccount:@"delete-me2" newService:@"delete-me2"],
                   errSecItemNotFound);

}

- (void)testBadPort {
    NSDictionary* addQuery = @{
        (id)kSecClass : (id)kSecClassInternetPassword,
        (id)kSecValueData : [@"password" dataUsingEncoding:NSUTF8StringEncoding],
        (id)kSecAttrAccount : @"SecItemTests testBadPort Account",
        (id)kSecAttrPort : @"",
    };

    OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addQuery, NULL);
    OSStatus expectedStatus = errSecParam;
#if TARGET_OS_IPHONE
    // Allow embedded OSes to work as before.
    expectedStatus = 0;
#endif
    XCTAssertEqual(status, expectedStatus);
}

static OSStatus CopyAllCertificatesMatchingEmail(CFStringRef emailAddress, CFArrayRef *certificates) {
    OSStatus result = errSecItemNotFound;
    if (!emailAddress) { return result; }
    CFMutableDictionaryRef  query = CFDictionaryCreateMutable(NULL, 0, NULL, NULL);

    CFDictionaryAddValue(query, kSecClass, kSecClassCertificate);
    CFDictionaryAddValue(query, kSecReturnRef, kCFBooleanTrue);
    CFDictionaryAddValue(query, kSecMatchEmailAddressIfPresent, emailAddress);
    CFDictionaryAddValue(query, kSecMatchLimit, kSecMatchLimitAll);

    result = SecItemCopyMatching(query, (CFTypeRef *)certificates);
    CFRelease(query);
    return result;
}

static CFIndex CertificatesFoundForEmail(CFStringRef emailAddress) {
    CFIndex certCount = -1; // invalid until we do the lookup
    CFArrayRef certs = NULL;
    OSStatus status = CopyAllCertificatesMatchingEmail(emailAddress, &certs);
    if (status == errSecItemNotFound) {
        certCount = 0;
    } else if (certs) {
        certCount = CFArrayGetCount(certs);
        CFRelease(certs);
    }
    return certCount;
}

- (void)test_data_protection_kc_no_email {
    // [105525994] This tests that a cert with the Digital Signature purpose
    // but no email address is *not* returned when email match is requested.
    // The reproducible case for this requires that the identity be added to
    // the DP keychain and is not synchronizable.
    CFDataRef message = CFDataCreateWithBytesNoCopy(kCFAllocatorDefault,
        _test_sign_no_email_p12, sizeof(_test_sign_no_email_p12), kCFAllocatorNull);
    CFArrayRef items = NULL;
    SecCertificateRef cert = NULL;
    SecKeyRef pkey = NULL;

    NSDictionary *options = @{
        (__bridge NSString*)kSecImportExportPassphrase : @"nick",
        (__bridge NSString*)kSecUseDataProtectionKeychain: @YES,
    };

    XCTAssertEqual(SecPKCS12Import(message, (__bridge CFDictionaryRef)options, &items), errSecSuccess, @"import to data protection kc");
    XCTAssertEqual(CFArrayGetCount(items), 1, @"one identity");
    CFDictionaryRef item = CFArrayGetValueAtIndex(items, 0);
    SecIdentityRef identity = NULL;
    identity = (SecIdentityRef)CFDictionaryGetValue(item, kSecImportItemIdentity);
    XCTAssertNotNil((__bridge id)identity, @"pull identity from imported data");

    XCTAssertEqual(CFGetTypeID(identity), SecIdentityGetTypeID(), @"this is a SecIdentityRef");
    XCTAssertEqual(SecIdentityCopyPrivateKey(identity, &pkey), errSecSuccess, @"get private key");
    XCTAssertEqual(SecIdentityCopyCertificate(identity, &cert), errSecSuccess, @"get certificate");

    // while the identity is present, run email match tests
    XCTAssertEqual(CertificatesFoundForEmail(CFSTR("hazmatteam6@apple.com")), 0, @"match email address");
    XCTAssertEqual(CertificatesFoundForEmail(CFSTR("")), 0, @"match empty string");
    XCTAssertEqual(CertificatesFoundForEmail(NULL), 0, @"match NULL string");

    NSDictionary *deleteMe = @{
        (id)kSecUseDataProtectionKeychain : @(YES),
        (id)kSecClass : (id)kSecClassCertificate,
        (id)kSecValueRef : (__bridge id)cert,
    };
    (void)SecItemDelete((__bridge CFDictionaryRef)deleteMe);
    deleteMe = @{
        (id)kSecUseDataProtectionKeychain : @(YES),
        (id)kSecClass : (id)kSecClassKey,
        (id)kSecValueRef : (__bridge id)pkey,
    };
    (void)SecItemDelete((__bridge CFDictionaryRef)deleteMe);

    CFReleaseNull(message);
    CFReleaseNull(items);
    CFReleaseNull(pkey);
    CFReleaseNull(cert);
}

//-MARK: helper functions

- (void)deleteAll {
    NSDictionary *allGenericPassword = @{
        (id)kSecClass : (id)kSecClassGenericPassword,
        (id)kSecUseDataProtectionKeychain : @(YES),
    };
    (void)SecItemDelete((__bridge CFDictionaryRef)allGenericPassword);

    NSDictionary *allInternetPassword = @{
        (id)kSecClass : (id)kSecClassInternetPassword,
        (id)kSecUseDataProtectionKeychain : @(YES),
    };
    (void)SecItemDelete((__bridge CFDictionaryRef)allInternetPassword);
}


- (NSDictionary *)addGenericPassword:(NSString *)account service:(NSString *)service
{
    NSDictionary* addQuery = @{
        (id)kSecClass : (id)kSecClassGenericPassword,
        (id)kSecValueData : [@"password" dataUsingEncoding:NSUTF8StringEncoding],
        (id)kSecAttrAccount : account,
        (id)kSecAttrService : service,
        (id)kSecAttrAccessible : (id)kSecAttrAccessibleAfterFirstUnlock,
        (id)kSecUseDataProtectionKeychain : @(YES),
        (id)kSecReturnAttributes : @(YES),
    };
    CFTypeRef result = NULL;

    OSStatus status = SecItemAdd((__bridge CFDictionaryRef)addQuery, &result);
    if (status != 0) {
        return @{ @"OSStatus": @(status) };
    }
    if (result == NULL) {
        return NULL;
    }
    if (CFGetTypeID(result) != CFDictionaryGetTypeID()) {
        CFRelease(result);
        return NULL;
    }

    return (__bridge NSDictionary *)result;
}


- (OSStatus)moveGenericPassword:(NSString *)account service:(NSString *)service
                     newAccount:(NSString *)newAccount newService:(NSString *)newService
{
    NSDictionary* updateQuery = @{
        (id)kSecClass : (id)kSecClassGenericPassword,
        (id)kSecValueData : [@"password" dataUsingEncoding:NSUTF8StringEncoding],
        (id)kSecAttrAccount : account,
        (id)kSecAttrService : service,
        (id)kSecAttrAccessible : (id)kSecAttrAccessibleAfterFirstUnlock,
        (id)kSecUseDataProtectionKeychain : @(YES),
    };
    NSDictionary *newAttributes = @{
        (id)kSecAttrAccount : newAccount,
        (id)kSecAttrService : newService,
    };

    OSStatus status = SecItemUpdate((__bridge CFDictionaryRef)updateQuery, (__bridge CFDictionaryRef)newAttributes);
    return status;
}

@end

unsigned char _test_sign_no_email_p12[2735] = {
  0x30, 0x82, 0x0a, 0xab, 0x02, 0x01, 0x03, 0x30, 0x82, 0x0a, 0x72, 0x06,
  0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82,
  0x0a, 0x63, 0x04, 0x82, 0x0a, 0x5f, 0x30, 0x82, 0x0a, 0x5b, 0x30, 0x82,
  0x04, 0xc7, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x07,
  0x06, 0xa0, 0x82, 0x04, 0xb8, 0x30, 0x82, 0x04, 0xb4, 0x02, 0x01, 0x00,
  0x30, 0x82, 0x04, 0xad, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
  0x01, 0x07, 0x01, 0x30, 0x1c, 0x06, 0x0a, 0x2a, 0x86, 0x48, 0x86, 0xf7,
  0x0d, 0x01, 0x0c, 0x01, 0x06, 0x30, 0x0e, 0x04, 0x08, 0x32, 0x7b, 0x61,
  0x65, 0xc3, 0x92, 0xd0, 0x5b, 0x02, 0x02, 0x08, 0x00, 0x80, 0x82, 0x04,
  0x80, 0xc2, 0xb7, 0xcc, 0x14, 0xbb, 0x0a, 0xda, 0xdd, 0xcf, 0x2e, 0xce,
  0x06, 0xdb, 0x4c, 0xef, 0xb3, 0xae, 0xe7, 0x2e, 0xb6, 0x9a, 0xf8, 0x79,
  0x32, 0xf2, 0xd7, 0x79, 0xff, 0x85, 0x08, 0xb3, 0x1e, 0x09, 0x3f, 0x30,
  0xf8, 0xb5, 0xa4, 0x28, 0x1c, 0x26, 0x58, 0xa2, 0xdf, 0xf3, 0xfc, 0xba,
  0x54, 0x80, 0x24, 0x72, 0xff, 0x74, 0x2e, 0x2e, 0x73, 0x47, 0xf1, 0x85,
  0x20, 0x55, 0xaa, 0x20, 0x62, 0x05, 0x30, 0xc4, 0x19, 0xe6, 0xe2, 0xa2,
  0xd5, 0x70, 0x86, 0x6b, 0xe2, 0x5a, 0xca, 0x7d, 0x43, 0xc4, 0xf1, 0x5e,
  0x62, 0xd8, 0xe7, 0x48, 0xab, 0xad, 0xa0, 0xa5, 0x01, 0x5d, 0xc4, 0xf0,
  0xf0, 0x17, 0xdb, 0x8b, 0x46, 0xb4, 0x34, 0xda, 0x98, 0xeb, 0x32, 0x8f,
  0xc6, 0x65, 0x51, 0x75, 0xae, 0xe9, 0x17, 0x04, 0x1e, 0x65, 0x8e, 0x82,
  0x1b, 0x62, 0x11, 0xfa, 0xe5, 0x31, 0xc9, 0x18, 0xbe, 0x6d, 0xea, 0x36,
  0x53, 0x09, 0xe7, 0xe8, 0xaa, 0xb0, 0x8a, 0x4d, 0xdc, 0x54, 0xf5, 0xef,
  0xa0, 0x8e, 0x60, 0x16, 0xb8, 0xd7, 0x48, 0xb2, 0x65, 0xb5, 0xf1, 0x38,
  0x38, 0x99, 0x54, 0xa8, 0x4f, 0x24, 0xc4, 0xcc, 0x2f, 0x60, 0x5c, 0xed,
  0x2a, 0x89, 0xab, 0xfe, 0x57, 0x49, 0x91, 0x35, 0x99, 0x79, 0x31, 0x55,
  0xd9, 0x04, 0x25, 0xb3, 0x75, 0x14, 0xac, 0xa4, 0x68, 0x13, 0x80, 0x8e,
  0xca, 0xb4, 0x62, 0xf6, 0x42, 0x3e, 0x43, 0x1c, 0x48, 0xd0, 0x82, 0x28,
  0xd6,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, 0x7d, 0x07, 0xd4, 0xa4, 0xbe, 0x9f, 0xb2, 0x72, 0x6e,
  0xa0, 0x26, 0x04, 0x3f, 0x28, 0x3e, 0xbd, 0xca, 0xd5, 0xf2, 0x45, 0x78,
  0x01, 0x99, 0x13, 0x35, 0xa7, 0xe6, 0xbc, 0x72, 0xa4, 0x68, 0xa1, 0xd3,
  0x43, 0xf6, 0xed, 0x39, 0xc3, 0x12, 0x99, 0x20, 0x9e, 0x59, 0xf4, 0x15,
  0xf7, 0x0f, 0xbe, 0xcf, 0x76, 0xda, 0x62, 0x90, 0x66, 0x16, 0xfd, 0xb1,
  0x16, 0x03, 0x51, 0x9f, 0x4a, 0xcc, 0x9c, 0xa9, 0xfc, 0xcc, 0x03, 0xcb,
  0xad, 0x2d, 0x27, 0x58, 0xbc, 0x80, 0xde, 0xeb, 0xf4, 0xf0, 0x45, 0xd6,
  0xde, 0x5a, 0xea, 0x52, 0x21, 0xf2, 0x56, 0xf9, 0x67, 0x52, 0x6c, 0x64,
  0xc5, 0x64, 0xd0, 0x6b, 0x4f, 0x21, 0x10, 0x9d, 0xfa, 0xc7, 0xac, 0xb0,
  0x20, 0x25, 0x91, 0x42, 0xaf, 0x95, 0x12, 0x15, 0x6e, 0xe4, 0x81, 0xce,
  0x27, 0x23, 0x4e, 0x65, 0x49, 0x3f, 0xb1, 0x09, 0x98, 0x7c, 0xe5, 0x4a,
  0xbf, 0xcf, 0xa0, 0x33, 0x34, 0x69, 0x65, 0x1b, 0xaa, 0x80, 0x2c, 0x0c,
  0x76, 0x6c, 0xbd, 0xa8, 0xfe, 0x6a, 0x94, 0x7b, 0x4d, 0xac, 0xfe, 0xd3,
  0xf1, 0x85, 0x43, 0x2e, 0x49, 0x9e, 0x94, 0x1c, 0xf1, 0xde, 0x38, 0xe6,
  0x6e, 0x88, 0xb4, 0x9b, 0xde, 0x65, 0x3c, 0x87, 0x0c, 0xef, 0x19, 0x9c,
  0x84, 0x5e, 0x97, 0x57, 0x1c, 0x39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e, 0x3c,
  0x4e, 0xbe, 0xb3, 0x3a, 0xc2, 0xb1, 0x7c, 0x36, 0x3a, 0x1c, 0x67, 0x11,
  0x30, 0x50, 0x67, 0x34, 0xd4, 0x4f, 0xae, 0x50, 0xeb, 0xbc, 0x04, 0x4b,
  0xcb, 0x01, 0xd4, 0xda, 0x6c, 0xdc, 0x73, 0x93, 0x60, 0x43, 0x0c, 0xd3,
  0x85, 0x30, 0x82, 0x05, 0x8c, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7,
  0x0d, 0x01, 0x07, 0x01, 0xa0, 0x82, 0x05, 0x7d, 0x04, 0x82, 0x05, 0x79,
  0x30, 0x82, 0x05, 0x75, 0x30, 0x82, 0x05, 0x71, 0x06, 0x0b, 0x2a, 0x86,
  0x48, 0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x0a, 0x01, 0x02, 0xa0, 0x82, 0x04,
  0xee, 0x30, 0x82, 0x04, 0xea, 0x30, 0x1c, 0x06, 0x0a, 0x2a, 0x86, 0x48,
  0x86, 0xf7, 0x0d, 0x01, 0x0c, 0x01, 0x03, 0x30, 0x0e, 0x04, 0x08, 0xfa,
  0xc7, 0x3e, 0xeb, 0xc2, 0xc1, 0x90, 0x3b, 0x02, 0x02, 0x08, 0x00, 0x04,
  0x82, 0x04, 0xc8, 0x82, 0xfb, 0x1d, 0x7f, 0xe0, 0x07, 0x9e, 0xb2, 0x7b,
  0x65, 0x83, 0xd2, 0x1c, 0x25, 0xeb, 0xd2, 0x34, 0xff, 0x32, 0x8c, 0x0e,
  0xf3, 0x7f, 0xee, 0xdc, 0x67, 0x9f, 0xc9, 0xb2, 0x94, 0x51, 0x95, 0xd2,
  0x27, 0x76, 0x26, 0xcc, 0x4a, 0x69, 0x8a, 0x72, 0x28, 0xa1, 0xe4, 0xd6,
  0xe5, 0xc0, 0x69, 0x66, 0xf0, 0x91, 0x63, 0x2a, 0xbc, 0x74, 0xdf, 0xbe,
  0x2f, 0x65, 0xfd, 0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, 0x31, 0x26,
  0x6e, 0x16, 0x15, 0xc1, 0x82, 0x22, 0x34, 0xad, 0xf4, 0x86, 0xd7, 0x0c,
  0xe2, 0x8d, 0x4d, 0x0e, 0xdf, 0xcc, 0x42, 0x31, 0xfe, 0xfe, 0xdb, 0xe8,
  0x33, 0x75, 0xd4, 0x9c, 0xfb, 0xe8, 0xd7, 0x73, 0xc3, 0x0e, 0xca, 0x57,
  0xdd, 0x56, 0x19, 0xa6, 0x8c, 0xf2, 0xfd, 0xc4, 0x17, 0xed, 0x21, 0x02,
  0x4c, 0x9a, 0x5f, 0x26, 0x72, 0xa9, 0xdc, 0x2b, 0x9a, 0xf9, 0xe7, 0x31,
  0x67, 0x2d, 0x19, 0x52, 0xb8, 0x4e, 0x9b, 0x18, 0x43, 0x2a, 0xea, 0x70,
  0xe2, 0x69, 0x43, 0x31, 0x70, 0x30, 0x49, 0x06, 0x09, 0x2a, 0x86, 0x48,
  0x86, 0xf7, 0x0d, 0x01, 0x09, 0x14, 0x31, 0x3c, 0x1e, 0x3a, 0x00, 0x48,
  0x00, 0x69, 0x00, 0x20, 0x00, 0x45, 0x00, 0x76, 0x00, 0x65, 0x00, 0x72,
  0x00, 0x79, 0x00, 0x62, 0x00, 0x6f, 0x00, 0x64, 0x00, 0x79, 0x00, 0x20,
  0x00, 0x49, 0x00, 0x74, 0x00, 0x27, 0x00, 0x73, 0x00, 0x20, 0x00, 0x4d,
  0x00, 0x65, 0x00, 0x20, 0x00, 0x44, 0x00, 0x72, 0x00, 0x2e, 0x00, 0x20,
  0x00, 0x4e, 0x00, 0x69, 0x00, 0x63, 0x00, 0x6b, 0x30, 0x23, 0x06, 0x09,
  0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x09, 0x15, 0x31, 0x16, 0x04,
  0x14, 0x74, 0xd0, 0x17, 0x92, 0x1a, 0xdc, 0x49, 0x05, 0xd3, 0x95, 0x71,
  0x7c, 0x09, 0xcf, 0x20, 0x5c, 0xd4, 0x7d, 0x51, 0x30, 0x30, 0x30, 0x30,
  0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00,
  0x04, 0x14, 0xac, 0x90, 0x41, 0xfd, 0xa1, 0x94, 0x5e, 0xe2, 0x18, 0x64,
  0x15, 0x74, 0x46, 0x5f, 0xb8, 0x06, 0xc3, 0x7e, 0x33, 0xb2, 0x04, 0x08,
  0x4d, 0x70, 0x2f, 0xa4, 0xa1, 0x95, 0x62, 0x12, 0x02, 0x01, 0x01
};
